
import {takeEvery, put} from 'redux-saga/effects';
import {GET_INIT_LIST} from './actionTypes';
import axios from 'axios';
import {getInitListAction} from './actionCreators';

function* getInitList() {
  try {
    const res = yield axios.get('/api/todolist');
    const action = getInitListAction(res.data);
    yield put(action);
  } catch(e) {
    console.log('失败')
  }
}

// saga文件的写法必须要求一个函数是generator函数
function* todoSaga() {
  yield takeEvery(GET_INIT_LIST, getInitList);
}

export default todoSaga;